package br.com.vti.sisp_sicrim.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.Validator;
import br.com.caelum.vraptor.view.Results;
import br.com.crud4j.core.model.business.Business;
import br.com.crud4j.core.util.MessageResolver;
import br.com.crud4j.vraptor3.controller.ControllerImpl;
import br.com.vti.sisp_sicrim.model.entity.Estado;
import br.com.vti.sisp_sicrim.model.entity.Municipio;
import br.com.vti.sisp_sicrim.modelo.business.exception.MunicipioException;

@Resource
@Path("/pages/municipio")
public class MunicipioController extends ControllerImpl<Municipio, MunicipioException> {

	@Autowired
	public MunicipioController(Result result, Validator validator, @Qualifier("municipioBusiness") Business<Municipio, MunicipioException> entidadeBusiness, MessageResolver messageResolver) {
		super(result, validator, entidadeBusiness, messageResolver);
		// TODO Auto-generated constructor stub
	}

	@Get("/lista/{estado.id}")
	public void getMunicipios(Estado estado) {
		Municipio municipio = new Municipio();
		municipio.setEstado(estado);
		List<Municipio> lista = getEntidadeBusiness().listar(municipio);
		getResult().use(Results.json()).withoutRoot().from(lista).serialize();
	}

}
